package org.linlinjava.litemall.db.service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.linlinjava.litemall.db.beans.Constants;
import org.linlinjava.litemall.db.dao.LitemallOrderMapper;
import org.linlinjava.litemall.db.dao.LitemallShopMapper;
import org.linlinjava.litemall.db.dao.OrderMapper;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.util.OrderUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import static org.linlinjava.litemall.db.beans.Constants.ORDER_STATUS_HANG;

/**
 * litemall订单服务
 *
 * @author yliyun
 * @date 2022/10/09
 */
@Service
public class LitemallOrderService extends MPJBaseServiceImpl<LitemallOrderMapper,LitemallOrder> {

        private LitemallOrder.Column[] CHANNEL = {LitemallOrder.Column.shopId, LitemallOrder.Column.orderPrice, LitemallOrder.Column.couponPrice};


    @Resource
    private LitemallOrderMapper litemallOrderMapper;

    @Resource
    private OrderMapper orderMapper;

    @Resource
    private LitemallShopMapper litemallShopMapper;

    public List<LitemallOrder> queryOrderWithUserId(Integer userId){
        return orderMapper.queryOrderWithUserId(userId);
    }

    public int add(LitemallOrder order) {

        return litemallOrderMapper.insertSelective(order);
    }

    public int count(Integer userId, List<Short> status) {
        return count(userId, status, false);
    }

    public int count(Integer userId, List<Short> status, Boolean today) {
        LitemallOrderExample example = new LitemallOrderExample();
        if (today != null && today) {
            LocalDateTime startTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
            LocalDateTime endTime = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
            if (userId != null) {
                example.or().andUserIdEqualTo(userId).andOrderStatusIn(status).andUpdateTimeBetween(startTime, endTime).andDeletedEqualTo(false);
            } else {
                example.or().andOrderStatusIn(status).andUpdateTimeBetween(startTime, endTime).andDeletedEqualTo(false);
            }
        } else {
            if (userId != null) {
                example.or().andUserIdEqualTo(userId).andOrderStatusIn(status).andDeletedEqualTo(false);
            } else {
                example.or().andOrderStatusIn(status).andDeletedEqualTo(false);
            }
        }
        return (int) litemallOrderMapper.countByExample(example);
    }

    public int countByShop(Integer shopId, List<Short> status, Boolean today) {
        LitemallOrderExample example = new LitemallOrderExample();
        if (today != null && today) {
            LocalDateTime startTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
            LocalDateTime endTime = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
            example.or().andShopIdEqualTo(shopId).andOrderStatusIn(status).andUpdateTimeBetween(startTime, endTime).andDeletedEqualTo(false);

        } else {
            example.or().andShopIdEqualTo(shopId).andOrderStatusIn(status).andDeletedEqualTo(false);

        }
        return (int) litemallOrderMapper.countByExample(example);
    }

    public LitemallOrder findById(Integer orderId) {
        return litemallOrderMapper.selectByPrimaryKey(orderId);
    }

    public List<LitemallOrder> findByIds(List<Integer> ids){
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andIdIn(ids).andDeletedEqualTo(false);
        return litemallOrderMapper.selectByExample(example);
    }

    public LitemallOrder findByUserAndId(Integer userId, Integer orderId) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andUserIdEqualTo(userId).andIdEqualTo(orderId).andDeletedEqualTo(false);
        return litemallOrderMapper.selectByPrimaryKey(orderId);
    }

    private String getRandomNum(Integer num) {
        String base = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < num; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    public int countByOrderSn(Integer userId, String orderSn) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andUserIdEqualTo(userId).andOrderSnEqualTo(orderSn).andDeletedEqualTo(false);
        return (int) litemallOrderMapper.countByExample(example);
    }

    // TODO 这里应该产生一个唯一的订单，但是实际上这里仍然存在两个订单相同的可能性
    public String generateOrderSn(Integer userId) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
        String now = df.format(LocalDateTime.now());
        String orderSn = now + getRandomNum(4);
        while (countByOrderSn(userId, orderSn) != 0) {
            orderSn = now + getRandomNum(4);
        }
        return orderSn;
    }

    public List<LitemallOrder> queryByOrderStatus(Integer userId, List<Short> orderStatus, Boolean today) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.setOrderByClause(LitemallOrder.Column.addTime.desc());
        LitemallOrderExample.Criteria criteria = example.or();
        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (orderStatus != null) {
            criteria.andOrderStatusIn(orderStatus);
        }
        if (today != null && today) {
            criteria.andUpdateTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));
        }
        criteria.andDeletedEqualTo(false);
        return litemallOrderMapper.selectByExample(example);
    }

//    public LitemallOrder> queryChannel(Integer orderId) {
//        LitemallOrderExample example = new LitemallOrderExample();
//        example.or().andIdEqualTo(orderId).andDeletedEqualTo(false);
//        return litemallOrderMapper.selectByExampleSelective(example, CHANNEL);
//    }

    public List<LitemallOrder> queryOrders(List<Integer> ids){
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.createCriteria();

        if(ids != null && ids.size() > 0){
            criteria.andIdIn(ids);
        }

        criteria.andDeletedEqualTo(false);
        return litemallOrderMapper.selectByExample(example);
    }

    /*public List<LitemallOrder> queryByOrderStatus(Integer userId, List<Short> orderStatus, Integer page, Integer limit, String sort, String order) {
        return queryTodayByOrderStatus(userId, false, orderStatus, page, limit, sort, order);
    }

    public List<LitemallOrder> queryTodayByOrderStatus(Integer userId, Boolean today, List<Short> orderStatus, Integer page, Integer limit, String sort, String order) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.setOrderByClause(LitemallOrder.Column.addTime.desc());
        LitemallOrderExample.Criteria criteria = example.or();

        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (orderStatus != null) {
            criteria.andOrderStatusIn(orderStatus);
        }
        if (today != null && today) {
            criteria.andUpdateTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));
        }
        criteria.andDeletedEqualTo(false);
        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        PageHelper.startPage(page, limit);
        return litemallOrderMapper.selectByExample(example);
    }*/

    public List<LitemallOrder> queryTodayNotInOrderStatus(Integer userId, Boolean today, List<Short> orderStatus, Integer page, Integer limit, String sort, String order,Integer shopId) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.setOrderByClause(LitemallOrder.Column.addTime.desc());
        LitemallOrderExample.Criteria criteria = example.or();

//        if (userId != null) {
//            criteria.andUserIdEqualTo(userId);
//        }
        if (orderStatus != null) {
            criteria.andOrderStatusIn(orderStatus);
        }
        if (shopId != null){
            criteria.andShopIdEqualTo(shopId);
        }
        if (today != null && today) {
            criteria.andAddTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));
        }

        criteria.andPayTypeNotEqualTo((byte) 6);

//        criteria.andOrderSourceEqualTo(Constants.ORDER_SOURCE_POS);

        criteria.andDeletedEqualTo(false);
        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        if(page != null && limit != null){
            //PageHelper.startPage(page, limit);
        }
        return litemallOrderMapper.selectByExample(example);
    }

    /*public List<LitemallOrder> queryByDateOrSn(String orderSn, LocalDate queryDate, List<Short> orderStatus, Integer page, Integer limit, String sort, String order,Integer shopId) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.setOrderByClause(LitemallOrder.Column.addTime.desc());
        LitemallOrderExample.Criteria criteria = example.or();

        if(orderSn != null && orderSn != "" ){
            criteria.andOrderSnLike("%" + orderSn + "%");
        }

        if(shopId != null){
            criteria.andShopIdEqualTo(shopId);
        }
        criteria.andPayTypeIsNotNull();
        *//*if (orderStatus != null) {
            criteria.andOrderStatusIn(orderStatus);
        }*//*
        if (queryDate != null ) {
            criteria.andAddTimeBetween(LocalDateTime.of(queryDate, LocalTime.MIN), LocalDateTime.of(queryDate, LocalTime.MAX));
        }


        criteria.andDeletedEqualTo(false);
        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        if(page != null && limit != null){
            PageHelper.startPage(page, limit);
        }
        return litemallOrderMapper.selectByExample(example);
    }*/

    /*public List<LitemallOrder> queryRefundByOrderSn(String orderSn, List<Short> orderStatus, Integer page, Integer limit, String sort, String order,Integer userId) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.setOrderByClause(LitemallOrder.Column.addTime.desc());
        LitemallOrderExample.Criteria criteria = example.or();

        if(orderSn != null && orderSn != "" ){
            criteria.andOrderSnLike( "%"+orderSn+"%");
        }

        if (orderStatus != null) {
            criteria.andOrderStatusIn(orderStatus);
        }


        criteria.andMadeStatusEqualTo((byte)0);

        criteria.andDeletedEqualTo(false);
        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        if(page != null && limit != null){
            PageHelper.startPage(page, limit);
        }
        return litemallOrderMapper.selectByExample(example);
    }*/

    /*public List<LitemallOrder> queryByOrderStatusAndEvaluationStatus(Integer userId, Byte evaluationStatus, List<Short> orderStatus, Integer page, Integer limit, String sort, String order) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.setOrderByClause(LitemallOrder.Column.addTime.desc());
        LitemallOrderExample.Criteria criteria = example.or();

        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (orderStatus != null) {
            criteria.andOrderStatusIn(orderStatus);
        }
        if (evaluationStatus != null) {
            criteria.andEvaluationStatusEqualTo(evaluationStatus);
        }

        //criteria.andExternalIdIsNull().andPayMemberIdIsNull();
        criteria.andPayMemberIdIsNull();

        criteria.andDeletedEqualTo(false);
        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        PageHelper.startPage(page, limit);
        return litemallOrderMapper.selectByExample(example);
    }*/

    /*public List<LitemallOrder> queryShopOrderByOrderStatus(Integer shopId, Boolean today, List<Short> orderStatus, Integer page, Integer limit, String sort, String order) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.setOrderByClause(LitemallOrder.Column.addTime.desc());
        LitemallOrderExample.Criteria criteria = example.or();

        if (shopId != null) {
            criteria.andShopIdEqualTo(shopId);
        }
        if (orderStatus != null) {
            criteria.andOrderStatusIn(orderStatus);
        }
        if (today != null && today) {
            criteria.andUpdateTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));
        }
        criteria.andDeletedEqualTo(false);
        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        PageHelper.startPage(page, limit);
        return litemallOrderMapper.selectByExample(example);
    }*/

    /*public List<LitemallOrder> querySelective(Integer id, Integer userId, String orderSn, List<Short> orderStatusArray, Byte orderType, Integer shopId, Integer page, Integer limit, String sort, String order) {
        List<Integer> userIds = new ArrayList<>();
        if (userId != null) {
            userIds.add(userId);
        }
        return querySelective(id, userIds, orderSn, orderStatusArray, orderType, shopId, page, limit, sort, order);
    }*/

    public List<LitemallOrder> querySelectiveForMember(Integer id, Integer userId, String orderSn, List<Short> orderStatusArray, Byte orderType, Integer shopId, Integer page, Integer limit, String sort, String order) {

        return querySelectiveForMem(id, userId, orderSn, orderStatusArray, orderType, shopId, page, limit, sort, order);
    }

    public List<LitemallOrder> querySelective(Integer id, List<Integer> userIds, String orderSn, List<Short> orderStatusArray, Byte orderType, Integer shopId, Integer page, Integer limit, String sort, String order) {
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.createCriteria();

        if (id != null) {
            criteria.andIdEqualTo(id);
        }
        if (userIds != null && userIds.size() > 0) {
            criteria.andUserIdIn(userIds);
        }
        if (!StringUtils.isEmpty(orderSn)) {
            criteria.andOrderSnLike("%" + orderSn + "%");
        }
        if (orderStatusArray != null && orderStatusArray.size() != 0) {
            criteria.andOrderStatusIn(orderStatusArray);
        }

        criteria.andExternalIdIsNull().andPayMemberIdIsNull();
        if (null != orderType) {
            criteria.andOrderTypeEqualTo(orderType);
        }

        if (null != shopId) {
            criteria.andShopIdEqualTo(shopId);
        }

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        criteria.andDeletedEqualTo(false);

//        criteria.andOrderSourceEqualTo(Constants.ORDER_SOURCE_APP);

        //PageHelper.startPage(page, limit);
        return litemallOrderMapper.selectByExample(example);
    }

    public List<LitemallOrder> querySelectiveForMem(Integer id, Integer userId, String orderSn, List<Short> orderStatusArray, Byte orderType, Integer shopId, Integer page, Integer limit, String sort, String order) {
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.createCriteria();

        if (id != null) {
            criteria.andIdEqualTo(id);
        }
        if (!StringUtils.isEmpty(orderSn)) {
            criteria.andOrderSnLike("%" + orderSn + "%");
        }
        if (orderStatusArray != null && orderStatusArray.size() != 0) {
            criteria.andOrderStatusIn(orderStatusArray);
        }

        //criteria.andExternalIdIsNull().andPayMemberIdIsNull();
        if (null != orderType) {
            criteria.andOrderTypeEqualTo(orderType);
        }

        if (null != shopId) {
            criteria.andShopIdEqualTo(shopId);
        }

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }
        //PageHelper.startPage(page, limit);
        return litemallOrderMapper.selectByExample(example);
    }

    public int updateWithOptimisticLocker(LitemallOrder order) {
        LocalDateTime preUpdateTime = order.getUpdateTime();
        order.setUpdateTime(LocalDateTime.now());
        return orderMapper.updateWithOptimisticLocker(preUpdateTime, order);
    }

    public void deleteById(Integer id) {
        litemallOrderMapper.deleteByPrimaryKey(id);
    }

    public void logicDeleteById(Integer id){
        litemallOrderMapper.logicalDeleteByPrimaryKey(id);
    }

    public int count2() {
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andPayMemberIdIsNull().andExternalIdIsNull().andDeletedEqualTo(false);
        return (int) litemallOrderMapper.countByExample(example);
    }

    public int countShop(Integer shopId) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andPayMemberIdIsNull().andExternalIdIsNull().andDeletedEqualTo(false).andShopIdEqualTo(shopId);
        return (int) litemallOrderMapper.countByExample(example);
    }

    public List<LitemallOrder> queryUnpaid(int minutes) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime expired = now.minusMinutes(minutes);
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andOrderStatusEqualTo(OrderUtil.STATUS_CREATE).andAddTimeLessThan(expired).andDeletedEqualTo(false);
        return litemallOrderMapper.selectByExample(example);
    }

    public List<LitemallOrder> queryUnconfirm(int days) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime expired = now.minusDays(days);
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andOrderStatusEqualTo(OrderUtil.STATUS_SHIP).andShipTimeLessThan(expired).andDeletedEqualTo(false);
        return litemallOrderMapper.selectByExample(example);
    }

    public LitemallOrder findBySn(String orderSn) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andOrderSnEqualTo(orderSn).andDeletedEqualTo(false);
        return litemallOrderMapper.selectOneByExample(example);
    }

    public LitemallOrder findByOrderSn(String orderSn) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andOrderSnLike(orderSn + "%").andDeletedEqualTo(false);
        return litemallOrderMapper.selectOneByExample(example);
    }

    public LitemallOrder findByPayId(String payId) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andPayIdEqualTo(payId).andDeletedEqualTo(false);
        return litemallOrderMapper.selectOneByExample(example);
    }

    public LitemallOrder findByOutTradeNo(String outTradeNo) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andOutTradeNoEqualTo(outTradeNo).andDeletedEqualTo(false);
        return litemallOrderMapper.selectOneByExample(example);
    }

    public LitemallOrder findByTransactionId(String transactionId){
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andTransationIdEqualTo(transactionId).andDeletedEqualTo(false);
        return litemallOrderMapper.selectOneByExample(example);
    }


    public Map<Object, Object> orderInfo(Integer userId) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false);
        List<LitemallOrder> orders = litemallOrderMapper.selectByExampleSelective(example, LitemallOrder.Column.orderStatus, LitemallOrder.Column.comments);

        int unpaid = 0;
        int unship = 0;
        int unrecv = 0;
        int uncomment = 0;
        for (LitemallOrder order : orders) {
            if (OrderUtil.isCreateStatus(order)) {
                unpaid++;
            } else if (OrderUtil.isPayStatus(order)) {
                unship++;
            } else if (OrderUtil.isShipStatus(order)) {
                unrecv++;
            } else if (OrderUtil.isConfirmStatus(order) || OrderUtil.isAutoConfirmStatus(order)) {
                uncomment += order.getComments();
            } else {
                // do nothing
            }
        }

        Map<Object, Object> orderInfo = new HashMap<Object, Object>();
        orderInfo.put("unpaid", unpaid);
        orderInfo.put("unship", unship);
        orderInfo.put("unrecv", unrecv);
        orderInfo.put("uncomment", uncomment);
        return orderInfo;

    }

    public List<LitemallOrder> queryComment(int days) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime expired = now.minusDays(days);
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andCommentsGreaterThan((short) 0).andConfirmTimeLessThan(expired).andDeletedEqualTo(false);
        return litemallOrderMapper.selectByExample(example);
    }

    public LitemallOrder queryGoodsStatistics(LocalDateTime startTime, LocalDateTime endTime, Integer shopId) {
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.or();
        if (!ObjectUtils.isEmpty(shopId)) {
            criteria.andShopIdEqualTo(shopId);
        }

//        criteria.andOrderSourceEqualTo(Constants.ORDER_SOURCE_APP);

        criteria.andExternalIdIsNull().andExIdIsNull().andPayMemberIdIsNull();
        criteria.andAddTimeBetween(startTime, endTime);
        criteria.andDeletedEqualTo(false);
        return litemallOrderMapper.selectOneByExample(example);
    }

    /**
     * 查询货物统计
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param shopId    商店id
     * @param payType   支付类型
     * @return {@link List}<{@link LitemallOrder}>
     */
    public List<LitemallOrder> queryGoodsStatisticsS(LocalDateTime startTime, LocalDateTime endTime,Integer shopId,Byte payType) {
        return litemallOrderMapper.selectList(Wrappers.lambdaQuery(LitemallOrder.class)
                .between(LitemallOrder::getAddTime,startTime,endTime)
                .eq(shopId!=null,LitemallOrder::getShopId,shopId)
                .eq(payType!=0,LitemallOrder::getPayType,payType)
                .isNull(LitemallOrder::getExternalId)
               // .isNull(LitemallOrder::getExId)
                .isNull(LitemallOrder::getPayMemberId)
                .eq(LitemallOrder::getDeleted,0)
        );
    }

    public List<LitemallOrder> selectList(LambdaQueryWrapper lambdaQueryWrapper) {
        return litemallOrderMapper.selectList(lambdaQueryWrapper);
    }

    public List<Map<String, Object>> queryGoodsSales(Integer shopId, LocalDateTime startTime, LocalDateTime endTime, Integer page, Integer limit) {
        Map<String, Object> map = new HashMap<>();
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        if (null != shopId) {
            map.put("shopId", shopId);
        }
        //PageHelper.startPage(page, limit);
        return orderMapper.queryGoodsSales(map);
    }

    public List<Map<String, Object>> queryGoodsCategorySales(LocalDateTime startTime, LocalDateTime endTime, Integer page, Integer limit) {
        Map<String, Object> map = new HashMap<>();
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        //PageHelper.startPage(page, limit);
        return orderMapper.queryGoodsCategorySales(map);
    }

    public List<Map<String, Object>> queryOrderGoodsNum(String type) {
        return orderMapper.queryOrderGoodsNum(type);
    }

    public List<LitemallOrder> querShopGoodsSalesInfo(Integer shopId, LocalDateTime startTime, LocalDateTime endTime) {
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.or();
        if (!ObjectUtils.isEmpty(shopId)) {
            criteria.andShopIdEqualTo(shopId);
        }
        criteria.andDeletedEqualTo(false);
        if (!ObjectUtils.isEmpty(startTime) && !ObjectUtils.isEmpty(endTime)) {
            criteria.andAddTimeBetween(startTime, endTime);
        }

        return litemallOrderMapper.selectByExample(example);
    }

    public List<LitemallOrder> querNotCompletedOrder(Integer shopId, LocalDateTime startTime, LocalDateTime endTime) {
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.or();
        if (!ObjectUtils.isEmpty(shopId)) {
            criteria.andShopIdEqualTo(shopId);
        }
        if (!ObjectUtils.isEmpty(startTime) && !ObjectUtils.isEmpty(endTime)) {
            criteria.andAddTimeBetween(startTime, endTime);
        }
        Short i = 401;
        Short ii = 402;
        criteria.andOrderStatusNotEqualTo(i);
        criteria.andOrderStatusNotEqualTo(ii);
        criteria.andDeletedEqualTo(false);
        return litemallOrderMapper.selectByExample(example);
    }

    public List<LitemallOrder> findByUserId(Integer userId) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false);
        return litemallOrderMapper.selectByExample(example);
    }

    public List<LitemallOrder> queryTime(LocalDateTime start, LocalDateTime end) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.setOrderByClause(LitemallOrder.Column.addTime.desc());
        LitemallOrderExample.Criteria criteria = example.or();
        criteria.andUpdateTimeBetween(start, end);
        criteria.andDeletedEqualTo(false);
        return litemallOrderMapper.selectByExample(example);
    }

    public int updateById2(LitemallOrder order) {
        order.setUpdateTime(LocalDateTime.now());
        return litemallOrderMapper.insert(order);
    }
    public int updateByIdEx(LitemallOrder order) {
        return litemallOrderMapper.updateByPrimaryKeySelective(order);
    }

    public int countTodayByExtendId(Integer externalId) {
        LitemallOrderExample example = new LitemallOrderExample();
        LocalDateTime start = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        LocalDateTime end = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        example.or().andExternalIdEqualTo(externalId).andAddTimeBetween(start, end).andDeletedEqualTo(false);
        return (int) litemallOrderMapper.countByExample(example);
    }


    public IPage<LitemallOrder> queryOrderSelective(Integer shopId, Integer userId, Boolean today, Short orderStatus, List<Byte> madeStatus, Integer page, Integer limit, String sort, String order) {

       LambdaQueryWrapper<LitemallOrder> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(shopId != null,LitemallOrder::getShopId,shopId);
        lambdaQueryWrapper.in(orderStatus != null,LitemallOrder::getOrderStatus,orderStatus);
        lambdaQueryWrapper.in(madeStatus != null && madeStatus.size() > 0 && orderStatus != null && orderStatus.equals((short)201),LitemallOrder::getMadeStatus,madeStatus);
        lambdaQueryWrapper.between(today != null && today,LitemallOrder::getAddTime,LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));
        lambdaQueryWrapper.eq(LitemallOrder::getDeleted,false);
        lambdaQueryWrapper.orderByDesc(LitemallOrder::getAddTime);
        return litemallOrderMapper.selectPage(new Page<>(page, limit),lambdaQueryWrapper);
    }

    /**
     * 查询机器的新建状态的订单
     *
     * @param shopId
     * @param deviceNo
     * @return
     */
    public LitemallOrder getNewOrder(Integer shopId, String deviceNo,Integer userId) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andShopIdEqualTo(shopId).andDeviceNoEqualTo(deviceNo)
                .andOrderStatusEqualTo(Constants.ORDER_STATUS_NEW).andUserIdEqualTo(userId).andDeletedEqualTo(false);
        return litemallOrderMapper.selectOneByExample(example);
    }

    /**
     * 查询今日店铺订单的最大序号
     *
     * @param shopId
     * @return
     */
    public Integer getTodayMaxSerialNo(Integer shopId) {
        return orderMapper.getTodayMaxSericalNo(shopId);
    }

    /**
     * 计算订单
     *
     * @param shopId
     * @param today
     * @param orderStatus
     * @param madeStatus
     * @return
     */
    public Long countOrderSelective(Integer shopId, Boolean today, Short orderStatus, Byte madeStatus) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.setOrderByClause(LitemallOrder.Column.addTime.desc());
        LitemallOrderExample.Criteria criteria = example.or();

        if (shopId != null) {
            criteria.andShopIdEqualTo(shopId);
        }

        if (orderStatus != null) {
            criteria.andOrderStatusEqualTo(orderStatus);
        }

        if (madeStatus != null) {
            criteria.andMadeStatusEqualTo(madeStatus);
        }

        if (today != null && today) {
            criteria.andUpdateTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));
        }
        criteria.andDeletedEqualTo(false);

        return litemallOrderMapper.countByExample(example);
    }

    /**
     * 计算订单数目
     *
     * @param shopId
     * @param today
     * @param orderStatusLs
     * @return
     */
    public Long countOrder(Integer shopId, List<Short> orderStatusLs, Boolean today) {
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.or();

        if (shopId != null) {
            criteria.andShopIdEqualTo(shopId);
        }

        if (!CollectionUtils.isEmpty(orderStatusLs)) {
            criteria.andOrderStatusIn(orderStatusLs);
        }

        if (today != null && today) {
            criteria.andUpdateTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));
        }
        criteria.andDeletedEqualTo(false);

        return litemallOrderMapper.countByExample(example);
    }

    /**
     * 根据条件查询超时订单
     *
     * @param orderStatus 订单状态
     * @param minutes     超时分钟
     * @return
     */
    public List<LitemallOrder> queryOverTime(Short orderStatus, int minutes) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime expired = now.minusMinutes(minutes);
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andOrderStatusEqualTo(orderStatus).andUpdateTimeLessThanOrEqualTo(expired).andDeletedEqualTo(false).andOrderSourceEqualTo((byte)1);
        return litemallOrderMapper.selectByExample(example);
    }

    /**
     * 月统计订单
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param regionId  区域id
     * @param shopId    店铺id
     * @return
     */
    public List<OrderMonthStatisticsVo> monthStatistics(String startTime, String endTime, Integer regionId, Integer shopId, Integer page, Integer limit) {
        //PageHelper.startPage(page, limit);
        return orderMapper.monthStatistics(startTime, endTime, regionId, shopId);
    }

    /**
     * @param startTime
     * @param endTime
     * @param shopId
     * @param page
     * @param limit
     * @return
     */
    public List<OrderDayStatisticsVo> dayStatistics(String startTime, String endTime, Integer shopId, Integer orderSource,Integer page, Integer limit) {
        //PageHelper.startPage(page, limit);
        return orderMapper.dayStatistics(startTime, endTime, shopId,orderSource);
    }

    /**
     * 小时统计订单
     *
     * @param searchDate 统计日期
     * @param time
     * @param shopId     店铺id
     * @return
     */
    public List<OrderHourStatisticsVo> hourStatistics(String searchDate, String time, Integer shopId, Integer page, Integer limit) {
        //PageHelper.startPage(page, limit);
        return orderMapper.hourStatistics(searchDate,time, shopId);
    }

    /**
     * 日统计详情
     *
     * @param searchDate
     * @param shopId
     * @param userIds
     * @param orderSn
     * @param page
     * @param limit
     * @return
     */
    public List<LitemallOrder> dayStatisticDetail(String searchDate, Integer shopId, List<Integer> userIds, String orderSn, Integer page, Integer limit) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.setOrderByClause(LitemallOrder.Column.addTime.desc());
        LitemallOrderExample.Criteria criteria = example.createCriteria();

        if (shopId != null) {
            criteria.andShopIdEqualTo(shopId);
        }

        if (!CollectionUtils.isEmpty(userIds)) {
            criteria.andUserIdIn(userIds);
        }

        if (!StringUtils.isEmpty(searchDate)) {
            DateTimeFormatter timeDtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDate searchLocalDate = LocalDate.parse(searchDate, timeDtf);
            criteria.andPayTimeBetween(LocalDateTime.of(searchLocalDate, LocalTime.MIN), LocalDateTime.of(searchLocalDate, LocalTime.MAX));
        }

        if (!StringUtils.isEmpty(orderSn)) {
            criteria.andOrderSnEqualTo(orderSn);
        }

        //criteria.andOrderStatusEqualTo(Constants.ORDER_STATUS_FINISHED);

        criteria.andDeletedEqualTo(false);
        //PageHelper.startPage(page, limit);

        return litemallOrderMapper.selectByExample(example);
    }

    /**
     * 订单汇总数统计
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param regionId  区域id
     * @param shopId    店铺id
     * @return
     */
    public OrderTotalStatisticsVo totalStatistics(String startTime, String endTime, Integer regionId, Integer shopId) {
        return orderMapper.totalStatistics(startTime, endTime, regionId, shopId);
    }
    public OrderRefundTotalStatisticsVo refundTotalStatistics(String startTime, String endTime, Integer regionId, Integer shopId) {
        return orderMapper.refundTotalStatistics(startTime, endTime, regionId, shopId);
    }
    public List<LitemallOrder> selectByExample(Integer externalId) {
        LitemallOrderExample example = new LitemallOrderExample();
        example.createCriteria().andExternalIdEqualTo(externalId);
        return litemallOrderMapper.selectByExample(example);
    }

    public IPage<LitemallOrder> selectByExample(Integer shopId,List<LocalDateTime> dateTime,List<LitemallUser> byName,Integer externalId,Byte orderType,Short orderStatus, Integer page, Integer limit) {
        LambdaQueryWrapper<LitemallOrder> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        Optional.ofNullable(orderType).ifPresent(type -> lambdaQueryWrapper.eq(LitemallOrder::getOrderType,type));
        Optional.ofNullable(orderStatus).ifPresent(status -> lambdaQueryWrapper.eq(LitemallOrder::getOrderStatus,status));
        Optional.ofNullable(shopId).ifPresent(value -> lambdaQueryWrapper.eq(LitemallOrder::getShopId,value));
        if(CollUtil.isNotEmpty(byName)){
            lambdaQueryWrapper.in(LitemallOrder::getUserId,byName.stream().map(LitemallUser::getId).collect(Collectors.toList()));
        }

        if(CollUtil.isNotEmpty(dateTime)){
            lambdaQueryWrapper.between(LitemallOrder::getAddTime,dateTime.get(0),dateTime.get(1));
        }
        return litemallOrderMapper.selectPage(new Page<>(page, limit),lambdaQueryWrapper);
    }

    public LitemallOrder selectByShop(Integer shopId, Integer orderId) {
        LitemallOrderExample example = new LitemallOrderExample();
        if (shopId != null) {
            example.or().andShopIdEqualTo(shopId);
        }

        if (orderId != null) {
            example.or().andIdEqualTo(orderId);
        }

        return litemallOrderMapper.selectOneByExample(example);
    }

    public List<LitemallOrder> queryByPointExchange(LocalDateTime startTime, LocalDateTime endTime, String sort, String order, Integer page, Integer size) {
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.createCriteria();
        if (startTime == null && endTime != null) {
            criteria.andPayTypeEqualTo(Constants.PAY_TYPE_POINT_EXCHANGE).andUpdateTimeLessThanOrEqualTo(endTime);
        } else if (endTime == null && startTime != null) {
            criteria.andPayTypeEqualTo(Constants.PAY_TYPE_POINT_EXCHANGE).andUpdateTimeGreaterThanOrEqualTo(startTime);
        } else if (endTime == null && startTime == null) {
            criteria.andPayTypeEqualTo(Constants.PAY_TYPE_POINT_EXCHANGE);
        } else {
            criteria.andPayTypeEqualTo(Constants.PAY_TYPE_POINT_EXCHANGE).andUpdateTimeBetween(startTime, endTime);
        }

//        criteria.andExIdIsNotNull();

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }


        //PageHelper.startPage(page, size);

        return litemallOrderMapper.selectByExample(example);
    }

    public List<LitemallOrder> queryByPointExchangeNoLimit(LocalDateTime startTime, LocalDateTime endTime) {
        LitemallOrderExample example = new LitemallOrderExample();
        if (startTime == null && endTime != null) {
            example.or().andPayTypeEqualTo(Constants.PAY_TYPE_POINT_EXCHANGE).andUpdateTimeLessThanOrEqualTo(endTime);
        } else if (endTime == null && startTime != null) {
            example.or().andPayTypeEqualTo(Constants.PAY_TYPE_POINT_EXCHANGE).andUpdateTimeGreaterThanOrEqualTo(startTime);
        } else if (endTime == null && startTime == null) {
            example.or().andPayTypeEqualTo(Constants.PAY_TYPE_POINT_EXCHANGE);
        } else {
            example.or().andPayTypeEqualTo(Constants.PAY_TYPE_POINT_EXCHANGE).andUpdateTimeBetween(startTime, endTime);
        }


        return litemallOrderMapper.selectByExample(example).stream().filter(order->order.getExId()!=null).collect(Collectors.toList());
    }

    public IPage<LitemallOrder> queryByExchangeId(Integer exchangeId, String sort, String order, Integer page, Integer size) {
        LambdaQueryWrapper<LitemallOrder> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(exchangeId != null,LitemallOrder::getPayType,Constants.PAY_TYPE_POINT_EXCHANGE);
        lambdaQueryWrapper.eq(exchangeId != null,LitemallOrder::getExId,exchangeId);

        lambdaQueryWrapper.eq(exchangeId == null,LitemallOrder::getPayType,Constants.PAY_TYPE_POINT_EXCHANGE);
        lambdaQueryWrapper.eq(exchangeId == null,LitemallOrder::getExId,exchangeId);
        lambdaQueryWrapper.orderByDesc(LitemallOrder::getAddTime);


        if(page != null && size != null){
            return litemallOrderMapper.selectPage(new Page<>(page,size),lambdaQueryWrapper);
        }
        return litemallOrderMapper.selectPage(new Page<>(1,-1),lambdaQueryWrapper);
    }

    public List<LitemallOrder> queryHangOrderList(Integer shopId,Integer userId){
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andShopIdEqualTo(shopId).andUserIdEqualTo(userId).andOrderStatusEqualTo(ORDER_STATUS_HANG).andDeletedEqualTo(false).
        andUpdateTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX)).
                andOrderSourceEqualTo(Constants.ORDER_SOURCE_POS);

        example.setOrderByClause("add_time" + " " + "desc");

        return litemallOrderMapper.selectByExample(example);
    }

    public List<LitemallOrder> queryLastOrder(Integer shopId){
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andShopIdEqualTo(shopId).andDeletedEqualTo(false).
                andOrderSourceEqualTo(Constants.ORDER_SOURCE_POS);

        example.setOrderByClause("add_time" + " " + "desc");

        return litemallOrderMapper.selectByExample(example);
    }

    public List<LitemallOrder> recipeDoingByMadeStatusInShop(List<Byte> madeStatus,Integer shopId) {
        LocalDateTime localDateTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        LocalDateTime localDateTime1 = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        LocalDateTime now = LocalDateTime.now();
        return litemallOrderMapper.selectList(Wrappers.lambdaQuery(LitemallOrder.class)
                .in(madeStatus.size()>0,LitemallOrder::getMadeStatus,madeStatus)
                //.isNull(LitemallOrder::getExternalId)
                .isNull(LitemallOrder::getPayMemberId)
                //.between(LitemallOrder::getPayTime,LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX))
                .between(LitemallOrder::getAddTime,LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX))
                .in(LitemallOrder::getOrderStatus,Constants.ORDER_STATUS_ONGOING,Constants.ORDER_STATUS_FINISHED)
                .eq(LitemallOrder::getDeleted,0)
                .eq(shopId!=null,LitemallOrder::getShopId,shopId)
                .orderByAsc(LitemallOrder::getAddTime)
        );
    }

    public List<LitemallOrder> recipeDoneByMadeStatusInShop(List<Byte> madeStatus, Integer shopId) {
        return litemallOrderMapper.selectList(Wrappers.lambdaQuery(LitemallOrder.class)
                .in(madeStatus.size()>0,LitemallOrder::getMadeStatus,madeStatus)
                //.isNull(LitemallOrder::getExternalId)
                .isNull(LitemallOrder::getPayMemberId)
                .between(LitemallOrder::getAddTime,LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX))
                .eq(LitemallOrder::getDeleted,0)
                .in(LitemallOrder::getOrderStatus,Constants.ORDER_STATUS_ONGOING,Constants.ORDER_STATUS_FINISHED,Constants.STATUS_REFUND,Constants.STATUS_REFUND_CONFIRM)
                .eq(shopId!=null,LitemallOrder::getShopId,shopId)
                .orderByDesc(LitemallOrder::getAddTime)
        );
    }

    public Integer queryNotPaid(Integer shopId,Integer userId) {
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.or();


        criteria.andExternalIdIsNull().andPayMemberIdIsNull();

        criteria.andAddTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));

        criteria.andOrderStatusEqualTo(Constants.ORDER_STATUS_NEW);
        if(userId != null){
            criteria.andUserIdEqualTo(userId);
        }
        criteria.andDeletedEqualTo(false);

        if(shopId != null ){
            criteria.andShopIdEqualTo(shopId);
        }
        return (int) litemallOrderMapper.countByExample(example);
    }

    public Integer queryPaid(Integer shopId,Integer userId) {
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.or();


        criteria.andExternalIdIsNull().andPayMemberIdIsNull();

        criteria.andAddTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));

        criteria.andOrderStatusEqualTo(Constants.ORDER_STATUS_ONGOING).andMadeStatusEqualTo((byte)0);

        if(shopId != null ){
            criteria.andShopIdEqualTo(shopId);
        }


        criteria.andDeletedEqualTo(false);
        return (int) litemallOrderMapper.countByExample(example);
    }

    public Integer queryNotPickUp(Integer shopId,Integer userId) {
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.or();


        criteria.andExternalIdIsNull().andPayMemberIdIsNull();

        criteria.andAddTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));

        criteria.andOrderStatusEqualTo(Constants.ORDER_STATUS_ONGOING).andMadeStatusEqualTo((byte)2);
        criteria.andDeletedEqualTo(false);

        if(shopId != null ){
            criteria.andShopIdEqualTo(shopId);
        }


        return (int) litemallOrderMapper.countByExample(example);
    }

    public Integer queryDone(Integer shopId,Integer userId) {
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.or();
        criteria.andExternalIdIsNull().andPayMemberIdIsNull();
        criteria.andAddTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));
        criteria.andOrderStatusEqualTo(Constants.ORDER_STATUS_FINISHED);
        criteria.andDeletedEqualTo(false);

        if(shopId != null ){
            criteria.andShopIdEqualTo(shopId);
        }



        return (int) litemallOrderMapper.countByExample(example);
    }

    public Integer queryHangOrder(Integer shopId,Integer userId) {
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.or();
        criteria.andExternalIdIsNull().andPayMemberIdIsNull();
        criteria.andAddTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));
        criteria.andOrderStatusEqualTo(Constants.ORDER_STATUS_HANG);
        criteria.andDeletedEqualTo(false);

        if(shopId != null ){
            criteria.andShopIdEqualTo(shopId);
        }


        return (int) litemallOrderMapper.countByExample(example);
    }

    public List<LitemallOrder> getNewOrderByUserId(Integer shopId,Integer userId){
        LitemallOrderExample example = new LitemallOrderExample();
        LitemallOrderExample.Criteria criteria = example.or();
        criteria.andExternalIdIsNull().andPayMemberIdIsNull();
        criteria.andOrderSourceEqualTo(Constants.ORDER_SOURCE_POS).andOrderStatusEqualTo(Constants.ORDER_STATUS_NEW);

        if(shopId != null){
            criteria.andShopIdEqualTo(shopId);
        }

        if(userId != null){
            criteria.andUserIdEqualTo(userId);
        }

        return litemallOrderMapper.selectByExample(example);
    }

    public Double totalOrderSumByUser(Integer userId) {
        return litemallOrderMapper.totalOrderSumByUser(userId);
    }

    //查询单个门店当天待收货订单
    public List<LitemallOrder> shopWaitDeliveryOrder(Short orderStatus,Integer shopId){
        LocalDateTime startTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        LocalDateTime endTime = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        LitemallOrderExample example = new LitemallOrderExample();
        example.or().andOrderStatusEqualTo(orderStatus).andShopIdEqualTo(shopId).andPayTimeBetween(startTime,endTime);
        List<LitemallOrder> orderList = litemallOrderMapper.selectByExample(example);
        return orderList;
    }

    //查询单个门店当天待收货以及待制作订单
//    public List<LitemallOrder> shopWaitDeliveryOrder(Short orderStatus,Integer shopId,Byte madeState){
//        LocalDateTime startTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
//        LocalDateTime endTime = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
//        LitemallOrderExample example = new LitemallOrderExample();
//        example.or().andOrderStatusEqualTo(orderStatus).andShopIdEqualTo(shopId).andMadeStatusEqualTo(madeState).andPayTimeBetween(startTime,endTime);
//        List<LitemallOrder> orderList = litemallOrderMapper.selectByExample(example);
//        return orderList;
//    }

}
